package com.windoent.yugioh.ui.activity.registlogin;

import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.baidu.mobstat.StatService;
import com.windoent.yugioh.AppManager;
import com.windoent.yugioh.MainActivity;
import com.windoent.yugioh.R;
import com.windoent.yugioh.base.BaseActivity;
import com.windoent.yugioh.utils.BaseMethod;
import com.windoent.yugioh.utils.ToastUtils;
import com.windoent.yugioh.widget.ActivityBackLeft;

/**
 * author : robert
 * date   : 2021/4/28 11:08
 * desc   :邮箱验证登录
 */
public class EmailLoginActivity extends BaseActivity implements View.OnClickListener {
    private LinearLayout llJump;
    private ActivityBackLeft back;
    private EditText etCellphone;
    private ImageView ivDelete;
    private Button btnGetCode;
    private View mView;


    @Override
    public int getLayout() {
        return R.layout.activity_email_login;
    }

    @Override
    public void initView() {
        super.initView();
        AppManager.getAppManager().addActivity(this);
        mView = (View) findViewById(R.id.view);

        immersiveStatusBar(mView);
        llJump = (LinearLayout) findViewById(R.id.ll_jump);
        back = (ActivityBackLeft) findViewById(R.id.back);
        etCellphone = (EditText) findViewById(R.id.et_cellphone);
        ivDelete = (ImageView) findViewById(R.id.iv_delete);
        btnGetCode = (Button) findViewById(R.id.btn_get_code);

    }

    @Override
    public void initData() {
        super.initData();
        ivDelete.setVisibility(View.GONE);
    }

    @Override
    public void initListener() {
        super.initListener();
        llJump.setOnClickListener(this);
        ivDelete.setOnClickListener(this);
        btnGetCode.setOnClickListener(this);
        back.setBackListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        etCellphone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                ivDelete.setVisibility(BaseMethod.notNull(charSequence.toString().trim()) && charSequence.toString().trim().length() > 0 ? View.VISIBLE : View.GONE);
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.ll_jump:
                startActivity(new Intent(EmailLoginActivity.this, MainActivity.class));
                AppManager.getAppManager().finishAllActivity();
                break;
            case R.id.iv_delete:
                etCellphone.setText("");
                break;
            case R.id.btn_get_code:
                //获取邮箱验证码
                String s = etCellphone.getText().toString().trim();
                if (BaseMethod.notNull(s) && s.length() > 0) {
                    Intent intent = new Intent(EmailLoginActivity.this, EmailCodeActivity.class);
                    intent.putExtra("email_code", s);
                    startActivity(intent);
                } else {
                    ToastUtils.showText(getString(R.string.string_email_hint));
                }
                break;
            default:
                break;
        }
    }
    @Override
    protected void onResume() {
        super.onResume();
        StatService.onPageStart(this, "登录注册邮箱验证登录界面");
    }

    @Override
    protected void onPause() {
        super.onPause();
        StatService.onPageEnd(this, "登录注册邮箱验证登录界面");
    }
}
